package appname.example.com.testmvvm;

import android.arch.lifecycle.Lifecycle;
import android.arch.lifecycle.LifecycleObserver;
import android.arch.lifecycle.OnLifecycleEvent;
import android.databinding.DataBindingUtil;
import android.databinding.ObservableField;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import java.util.ArrayList;

import appname.example.com.testmvvm.databinding.ActivityMainBinding;



// mvvm相关的
public class MainActivity extends AppCompatActivity {

    //  想要 ObservableField 那么需要使用的是 binding的set方法
    public ObservableField<Testbean> name = new ObservableField<>();

    private ArrayList<Testbean> datas =new ArrayList<>();


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_main);
        // todo 普通的 viewdatabinding 是没办法 查找到id的，只有布局相对应的 viewdatabinding 才行
        ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
        // name.set(bean1);
        // binding.setData(bean1);
        // todo 只要bean1的状态改了，布局中的数据能够立即改变
        // bean1.setName("6666");

        binding.setCtrl(new MainCtrl(binding));


        test();
    }


    private void test(){
        getLifecycle().addObserver(new LifecycleObserver() {

            @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
            void onResume(){
                Log.e("111", "LifecycleObserver onResume() called");
            }
        });
    }


    @Override
    protected void onStop() {
        super.onStop();
        Log.e("111", "onstop");

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.e("111", "onDestroy");

    }
}
